import pandas as pd
from matplotlib import pyplot as plt
import matplotlib

matplotlib.rc("font", family='Source Han Sans CN', weight="regular", size="10")

file_path = "csv/BeijingPM20100101_20151231.csv"
df = pd.read_csv(file_path)

df["datetime"] = pd.PeriodIndex(year=df["year"], month=df["month"], day=df["day"], hour=df["hour"], freq="H")
df.set_index("datetime", inplace=True)
data_us = df["PM_US Post"].resample("7D").mean()
data_china = df["PM_Dongsi"].resample("7D").mean()

plt.figure(figsize=(20, 8), dpi=80)
plt.xlabel("时间")
plt.ylabel("PM2.5")
plt.title("PM2.5周平均值随时间变化统计图", weight="bold", size="16")

_x_us = data_us.index
_y_us = data_us.values
_x_china = data_china.index
_y_china = data_china.values
plt.xticks(range(0, len(_x_us), 10), list(_x_us)[::10], rotation=45)

plt.plot(range(len(_x_us)), _y_us, label="us")
plt.plot(range(len(_x_china)), _y_china, label="china")
plt.legend()
plt.show()
